namespace CSharpPro._10_20_02;

public class Student
{
    private int _studentID;
    private string _name;
    private int _age;
    private List<double> _grades = new List<double>();
 
    public int StudentID 
    {
        get => _studentID;
        set => _studentID = value > 0 ? value : throw new ArgumentException("学号必须为正整数");
    }
 
    public string Name 
    {
        get => _name;
        set => _name = !string.IsNullOrWhiteSpace(value) ? value : throw new ArgumentException("姓名不能为空");
    }
 
    public int Age 
    {
        get => _age;
        set => _age = value >= 0 && value <= 150 ? value : throw new ArgumentException("年龄范围0-150岁");
    }
    public double AverageGrade => _grades.Count > 0 ? _grades.Average() : 0;
 
   
    public Student(int studentID, string name, int age)
    {
        StudentID = studentID;
        Name = name;
        Age = age;
    }
    public void AddGrade(double grade)
    {
        if (grade >= 0 && grade <= 100)
            _grades.Add(grade);
        else
            throw new ArgumentException("成绩必须在0-100分之间");
    }
    public void DisplayInfo()
    {
        Console.WriteLine($"学号: {StudentID}");
        Console.WriteLine($"姓名: {Name}");
        Console.WriteLine($"年龄: {Age}");
        Console.WriteLine($"当前平均分: {AverageGrade:F2}");
        Console.WriteLine($"已修课程数: {_grades.Count}");
    }
    public bool IsPassing() => AverageGrade >= 60;
}
